home *** CD-ROM | disk | FTP | other *** search
/ D.I.S.C. 5 / D.I.S.C. 5.adf / sources / direct_selection.s < prev   
Text File  |  1989-01-11  |  2KB  |  56 lines

  1. ; ----------------------------------------------------------------
  2. ; --- implementation of the direct-selection sorting algorithm ---
  3. ; --- done by JPN/Level 4-ASD in August 1990 (assembly version)---
  4. ; --- This is the non-optimized version                        ---
  5. ; --- program sorts data sized as words from 'data_list'       ---
  6. ; --- program processes 16 bit signed data (-32768 -> +32767)  ---
  7. ; --- 'num_elements' features the number of elements to sort   ---
  8. ; --- routine length : 64 ($40) bytes                          ---
  9. ; --- any questions? Call Germany: (0)631/43752 (KRIS)         ---
  10. ; ----------------------------------------------------------------
  11.  
  12. org    $40000
  13. load    $40000
  14.  
  15. num_elements=100
  16.  
  17. a:
  18.         lea    data_list,a0        ; table for elements
  19.         moveq    #00,d0            ; outer loop counter (x)
  20. outer:    
  21.         move.w    d0,d1            ; inner loop counter (y)
  22.         move.w    d0,d2            ; index for smallest (j=x)
  23. inner:                    
  24.         move.w    (a0,d1.w),d3        ; a(y) -> d3        
  25.         cmp.w    (a0,d2.w),d3        ; a(j) < a(y) ???
  26.         bgt    smaller            
  27.         move.w    d1,d2            ; j=y
  28. smaller:                
  29.         addq.w    #02,d1            ; next y value
  30.         cmp.w    #num_elements*2,d1    ; end of inner loop ?
  31.         bne    inner            ; next y
  32.         move.w    (a0,d2.w),d3        ; a(j) -> d3
  33.         move.w    (a0,d0.w),d4        ; a(x) => d4
  34.         move.w    d3,(a0,d0.w)        ; exchange    
  35.         move.w    d4,(a0,d2.w)        ; the numbers (d3, d4)
  36.         addq.w    #02,d0            ; next x value
  37.         cmp.w    #num_elements*2,d0    ; end of outer loop
  38.         bne    outer            ; next x
  39.         rts            
  40. end_of_routine:
  41.  
  42. data_list:
  43.     dc.w 5,2,3,1,6,8,9,7,4,0
  44.     dc.w 5,2,3,-1,6,8,9,7,4,0
  45.     dc.w 5,2,3,-2,6,8,9,7,4,0
  46.     dc.w 5,2,3,1,6,8,9,7,4,0
  47.     dc.w 5,2,3,1,6,8,9,7,4,0
  48.     dc.w 5,2,3,1,6,8,9,7,4,0
  49.     dc.w 5,2,3,1,6,8,9,7,4,0
  50.     dc.w 5,2,3,1,6,8,9,7,4,0
  51.     dc.w 5,2,3,1,6,8,9,7,4,0
  52.     dc.w 5,2,3,1,6,8,9,7,4,0
  53.  
  54.  
  55.  
  56.